package org.raymond.iworks.study.example;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.junit.jupiter.api.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Locale;

@Slf4j
public class DateTest {

    @Test
    public void test1() throws ParseException {
        Date date = DateUtils.parseDate("2022/10/21", "yyyy/MM/dd");
        String str = DateFormatUtils.format(date, "dd/MM/YY");

        log.info("date: {}", str);
    }

    @Test
    public void test2() throws ParseException {
        Date date = DateUtils.parseDate("2022/12/01", "yyyy/MM/dd");
        SimpleDateFormat sdf = new SimpleDateFormat("MMMM dd , yyyy", Locale.ENGLISH);
        String str = sdf.format(date);
        log.info("date: {}", str);
    }

    @Test
    public void test3(){
        Date d = new Date();
        //Date n = new Date(d.getTime()+1000);
        Date n = DateUtils.addSeconds(d, 1);
        String ds = DateFormatUtils.format(d, "dd/MM/YYYY HH:mm:ss.SSS");
        String ns = DateFormatUtils.format(n, "dd/MM/YYYY HH:mm:ss.SSS");
        log.info("d:{}, n:{}", ds, ns);
    }

    @Test
    public void test4(){
        LocalDateTime ldt = LocalDateTime.now().atZone(ZoneOffset.ofHours(8)).toLocalDateTime();
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS", Locale.CHINA);
        log.info(dtf.format(ldt));
    }
}
